﻿﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrossesGrav.GameLogic;
using CrossesGrav.WorkClasses;
using System.Drawing;

namespace CrossesGrav
{
    static class Game 
    {

        static public List<PictureBox> menu_items = new List<PictureBox>();
        static int temp_coord;
        static public  bool menu_click = false;
        static public float forWin;
        static public Player plr = null;
        static public bool GameOver = false;
        static public List<Cell> AvalibleCells = new List<Cell>();
       // static public List<Bitmap> images = new List<Bitmap>();
        static public ARGBFont fonts = new ARGBFont(global::CrossesGrav.Properties.Resources.fonts_RU_EN1, @"АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчЩщШшЪъЫыЬьЭэЮюЯяAaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890!@#$%^&*()_-+/|\.,<>~"+'"'+"` №’«»[]{}");
        static public object now_clicked;
        static public bool can_be_clicked;
        static public int menu_layout = -1;
        static public int movements;

        static public ArrDictionary<string, Bitmap> images = new ArrDictionary<string, Bitmap>();

       ///////////////////////////
       // static public bool test = false;
        //static public int[] see_cells = new int[0];
       // static public int see_cells = 0;

        //static public List<string> logs = new List<string>();
        //static public ArrDictionary<int, string> logs_X = new ArrDictionary<int, string>();
       // static public ArrDictionary<int, string> logs_O = new ArrDictionary<int, string>();

        ///////////////////////////////
        // УДАЛИТЬ

        //static public List<TextBox> tmpInd = new List<TextBox>();
        //static public List<TextBox> tmpInd1 = new List<TextBox>();
       // static public List<TextBox> tmpInd2 = new List<TextBox>();

        // УДАЛИТЬ

        public static void Click_Item(object sender, MouseEventArgs e)
        {
            if ((!menu_click)&&(now_clicked==null))
            {
                now_clicked = sender;
                menu_click = !menu_click;

                for (int i = 0; i < menu_items.Count; i++)
                {
                    if (sender != menu_items[i])
                    {
                        menu_items[i].Visible = false;
                    }

                    else
                    {
                        temp_coord = (sender as PictureBox).Top;
                        (sender as PictureBox).Top = 35;
                        //menu_layout = i;
                        can_be_clicked = false;
                        Program.f.MakeLayout(i);
                    }
                }

            }
            else
                if ((now_clicked == sender)&&(can_be_clicked))
                {
                    (sender as PictureBox).BorderStyle = BorderStyle.None;
                    now_clicked = null;
                    menu_click = !menu_click;

                    for (int i = 0; i < menu_items.Count; i++)
                    {
                        if (sender != menu_items[i])
                        {
                            menu_items[i].Visible = true;
                        }

                        else
                        {
                            (sender as PictureBox).Top = temp_coord;
                        }
                    }
                } 
        }

         public static void lets_game(List<Player> p)
        {
            while (!GameOver)
            {
                if (GameOver == false)
                {
                    if (movements != 0)
                    {
                        if ((p[0].moving == true) && (p[0].can_click == true))
                        {
                            plr = p[0];
                        }
                        else
                        {
                            if (p[1].can_click == true)
                            {
                                plr = p[1];
                            }
                        }
                        try
                        {
                            Form1.ActiveForm.Refresh();
                        }
                        catch
                        {
                            //do nothink
                        }
                        plr.Move(movements);
                        Program.f.Refresh();
                        if (plr.GetType().Name == "Human")
                            break; 

                    }
                    else
                    {
                        //MessageBox.Show("Клетки кончились:)");

                        GameOver = true;
                        ////////////////////
                        //Program.f.pictureBox6_Click(new object(), new EventArgs());
                        ///////////////////

                        for (int i = 0; i < p.Count; i++)
                        {
                            p[i].can_click = false;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < p.Count; i++)
                    {
                        p[i].can_click = false;
                    }
                }
            }
        }

    }
}